#include <iostream>
#include <algorithm>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define int long long
#define PII pair<int, int>

void solve()
{
    int n, m, ans = 0, mx = 0; cin >> n >> m;
    vector<int> b(m);
    priority_queue<int, vector<int>, greater<int>> a, del, equ;
    priority_queue<PII, vector<PII>, greater<PII>> add;
    for (int i = 0; i < n; ++i) {
        int tmp; cin >> tmp; a.push(tmp);
        mx = max(mx, tmp);
    }
    for (auto& e : b) cin >> e;
    for (int i = 0; i < m; ++i) {
        int c; cin >> c;
        if (c == 0) del.push(b[i]);
        else if (c <= b[i]) equ.push(b[i]);
        else add.push({ b[i], c });
    }
    vector<int> tmp;
    while (a.size() && add.size()) {
        if (a.top() < add.top().first) {
            //cout << "a.top" << a.top() << "move" << endl;
            tmp.push_back(a.top()); a.pop();
        }
        else {
            //cout << "a.top" << a.top() << ", add.top" << add.top().first << ' ' << add.top().second << endl;
            int tmp = max(a.top(), add.top().second);
            a.pop();
            add.pop();
            a.push(tmp);
            mx = max(mx, tmp);
            ++ans;
        }
    }
    for (auto& e : tmp) a.push(e); tmp.clear();
    while (equ.size() && mx >= equ.top()) {
        ++ans; equ.pop();
    }
    while (a.size() && del.size()) {
        if (a.top() < del.top()) {
            a.pop();
        }
        else {
            del.pop();
            a.pop();
            ++ans;
        }
    }
    cout << ans << endl;
}

signed main()
{
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int t; cin >> t;
    while (t--) solve();
    return 0;
}